package com.qin.mall.controller.productcontroller;

import com.qin.mall.openfeign.product.BrandService;
import com.qin.mall.common.api.CommonResult;
import com.qin.mall.common.api.MyBatisPlusPage;
import com.qin.mall.domain.PmsBrand;
import com.qin.mall.dto.BrandDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 品牌功能Controller
 * @author Leisure
 * create 2022 2022/11/19 10:59
 **/
@RestController
@RequestMapping("/brand")
public class PmsBrandController {
    @Autowired
    private BrandService brandService;

    //查询所有品牌
    @GetMapping("/listAll")
    @ResponseBody
    public CommonResult<List<PmsBrand>> agetList() {
        return brandService.getBrandList$();
    }
    
    //创建品牌
    @PostMapping("/create")
    @ResponseBody
    public CommonResult create(@RequestBody BrandDto brandDto) {
        CommonResult brand = brandService.insetBrand$(brandDto);
        return brand;
    }
    
    //更新品牌
    @PostMapping("/update/")
    public CommonResult updateBrand(@RequestParam(value = "id") Long id,
                              @RequestBody BrandDto brandDto){
        CommonResult count = brandService.updateBrand$(id, brandDto);
        return count;
    }
    
    //通过id删除品牌
    @GetMapping("/delete/{id}")
    public CommonResult deleteBrand(@PathVariable("id") Long id){
        CommonResult count = brandService.deleteBrand$(id);
        return count;
    }

    //批量删除品牌
    @PostMapping("/delete/batch")
    public CommonResult deleteBrands(@RequestBody List<Long> ids){
        CommonResult count = brandService.deleteBrands$(ids);
        return count;
    }
    
    //关键字分页查询品牌
    @GetMapping("/list")
    @ResponseBody
    public CommonResult<MyBatisPlusPage<PmsBrand>> getList(@RequestParam(value = "keyword", required = false) String keyword,
                                                           @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                           @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        CommonResult<MyBatisPlusPage<PmsBrand>> brandList  = brandService.selectListBrand$(keyword, pageNum, pageSize);
        return brandList;
    }

    //通过id获取品牌
    @GetMapping("/selectById")
    public CommonResult<PmsBrand> selectInId(@RequestParam(value = "id") Long id){
        CommonResult<PmsBrand> brand = brandService.selectById$(id);
        return brand;
    }

    //批量更新显示状态
    @PostMapping("/update/showStatus")
    public CommonResult updateShowStatus(@RequestParam("ids") List<Long> ids,
                                   @RequestParam(value = "showStatus") Integer showStatus){
        CommonResult count = brandService.updateShowStatus$(ids, showStatus);
        return count;
    }

    //批量更新厂家制造商状态
    @PostMapping("/update/factoryStatus")
    public CommonResult updateFactoryStatus(@RequestParam("ids") List<Long> ids,
                                      @RequestParam(value = "factoryStatus") Integer factoryStatus){
        CommonResult count = brandService.updateFactoryStatus$(ids, factoryStatus);
        return count;
    }


    //TODO 通过id获取品牌
    @GetMapping("/{id}")
    public CommonResult<PmsBrand> selectById$(@PathVariable("id") Long id){
        CommonResult<PmsBrand> result = brandService.selectById$(id);
        return result;
    }

}
